//
//  QSWebErrorView.swift
//  TestSwift
//
//  Created by Song on 2018/7/3.
//  Copyright © 2018年 Song. All rights reserved.
//

import UIKit

class QSWebErrorView: UIView {
    /// 点击刷新的Block
    var reloadBlock: (() -> ())?
    
    init(with reloadBlock: @escaping (() -> ())) {
        super.init(frame: CGRect.zero)
        
        self.reloadBlock = reloadBlock
        self.setupSubViews()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupSubViews() {
        // imgView
        let imgView = UIImageView.init()
        self.addSubview(imgView)
        imgView.snp.makeConstraints { (make) in
            make.centerX.equalTo(self)
            make.top.equalTo(182.0)
            make.width.height.equalTo(135.0)
        }
        
        imgView.image = UIImage.init(named: "icon_universa_loading_failure2")
        
        // reloadBtn
        let reloadBtn = UIButton.init()
        self.addSubview(reloadBtn)
        reloadBtn.snp.makeConstraints { (make) in
            make.centerX.equalTo(imgView)
            make.top.equalTo(imgView.snp.bottom).offset(38.0)
            make.width.equalTo(98.0)
            make.height.equalTo(30.0)
        }
        
        reloadBtn.setTitle("点我重新加载", for: UIControlState.normal)
        reloadBtn.titleLabel?.font = UIFont.systemFont(ofSize: 12.0)
        reloadBtn.setTitleColor(UIColor.init(red: 96.0, green: 202.0, blue: 234.0, alpha: 1.0), for: UIControlState.normal)
        reloadBtn.qs_setAction { (btn) in
            if self.reloadBlock != nil {
                self.reloadBlock!()
            }
        }
    }
}
